
/* Generated by Interface Builder */

#import "Proto.h"

@implementation Proto

+ new:(char *)atypename:(char *)apathname:(char *)aneditor:(int)open
{
	return [[[[[self new]
		setTypename:atypename]
		setPathname:apathname]
		setEditor:aneditor]
		setDefaultopen:open];
}

// Create a new proto by reading data from file.
+ read:(FILE *)fp
{
	id proto;
	int	cont;
	char	atypename[NAME_LENGTH], apathname[MAXPATHLEN], aneditor[NAME_LENGTH];
	char	openstr[10];
	int	open;
	
	cont = fscanf(fp, "typename = %[^,], pathname = %[^,], editor = %[^,], open = %s\n", atypename, apathname, aneditor, openstr);

	if (cont==4)
	{
		if (strcmp(openstr, WS_STR)==0)
			open = OPEN_WS;
		else if (strcmp(openstr, EDITOR_STR)==0)
			open = OPEN_EDITOR;
		else
			open = DONT_OPEN;
		
		if (strcmp(aneditor, NULL_EDITOR)==0)
			strcpy(aneditor, "");
			
		proto = [Proto new:atypename:apathname:aneditor:open];
	}
	else
		proto = nil;
	return proto;
}

- (char *)typename
{
	return typename;
}

- setTypename:(char *)str
{
	strcpy(typename, str);
	return self;
}

- (char *)pathname
{
	return pathname;
}

- setPathname:(char *)str
{
	strcpy(pathname, str);
	return self;
}

- (char *)editor
{
	return editor;
}

- setEditor:(char *)str
{
	strcpy(editor, str);
	return self;
}


- (int)defaultopen
{
	return defaultopen;
}

- setDefaultopen:(int)def
{
	defaultopen = def;
	return self;
}


// The extension of the prototype file. Returns "" if there is no extension.
- (char *)extension
{
	char *ext;
	ext = rindex([self pathname], '.');
	if (ext==0)
		ext = "";
	else
		ext++;
	return ext;
}

- write:(FILE *)fp
{
	char *openstr, *aneditor;
	int	open = [self defaultopen];
	if (open == OPEN_EDITOR)
		openstr = EDITOR_STR;
	else if (open == OPEN_WS)
		openstr = WS_STR;
	else
		openstr = DONT_STR;
	
	if (strcmp([self editor], "")==0)
		aneditor = "/dev/null";
	else
		aneditor = [self editor];
	fprintf(fp, "typename = %s, pathname = %s, editor = %s, open = %s\n", [self typename], [self pathname], aneditor, openstr);
	return self;
}

@end
